using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for FoldersAdaptor.
	/// </summary>
	public class FoldersAdaptor : Adaptor, IRefreshable
	{
    private FolderCollection folders;
		public FoldersAdaptor(FolderCollection folders)
		{
      this.folders = folders;
		}

    public override void AddChildren(TreeNode node)
    {
      foreach (Folder folder in folders)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new FolderAdaptor(folder));
        node.Nodes.Add(childNode);
      }
    }

    public override int ImageIndex
    {
      get
      {
        return 9;
      }
    }

    public override string Text
    {
      get
      {
        return "Folders (" + folders.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      FoldersControl control = new FoldersControl();
      control.LoadFolders(folders);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return folders;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      folders.Refresh();
    }

    #endregion
  }
}
